#ifndef JSON_OBJECT_BASE_HXX
#define JSON_OBJECT_BASE_HXX

#include "CJsonObject.hpp"

#define ASJsonCommandMap(MACRO)                                                             \
  MACRO(ChannelCtrl,                "ChannelCtrl",              ASChannelCtrl)              \
  MACRO(ConfigMSNotify,             "ConfigMSNotify",           ASConfigMSNotify)           \
  MACRO(CreateConf,                 "CreateConf",               ASCreateConf)               \
  MACRO(DestroyConf,                "DestroyConf",              ASDestroyConf)              \
  MACRO(InteractiveCtrl,            "InteractiveCtrl",          ASInteractiveCtrl)          \
  MACRO(JoinConf,                   "JoinConf",                 ASJoinConf)                 \
  MACRO(LeaveConf,                  "LeaveConf",                ASLeaveConf)                \
  MACRO(LiveStart,                  "LiveStart",                ASLiveStart)                \
  MACRO(LiveStop,                   "LiveStop",                 ASLiveStop)                 \
  MACRO(Mix,                        "Mix",                      ASMix)                      \
  MACRO(QueryAllRegisterUser,       "QueryAllRegisterUser",     ASQueryAllRegisterUser)     \
  MACRO(QueryConfStat,              "QueryConfStat",            ASQueryConfStat)            \
  MACRO(QueryInteractiveCtrlStat,   "QueryInteractiveCtrlStat", ASQueryInteractiveCtrlStat) \
  MACRO(QueryMSInfo,                "QueryMSInfo",              ASQueryMSInfo)              \
  MACRO(QueryUserStat,              "QueryUserStat",            ASQueryUserStat)            \
  MACRO(RecordQuery,                "RecordQuery",              ASRecordQuery)              \
  MACRO(RecordStart,                "RecordStart",              ASRecordStart)              \
  MACRO(RecordStop,                 "RecordStop",               ASRecordStop)               \
  MACRO(SessionIPChanged,           "SessionIPChanged",         ASSessionIPChanged)


class JsonObject : public neb::CJsonObject
{
public:
    typedef enum Type
    {
        Unknown,
#undef defineType
#define defineType(_enum, _name, _type) Request##_enum,
        ASJsonCommandMap(defineType)
#undef defineType
#define defineType(_enum, _name, _type) Response##_enum,
        ASJsonCommandMap(defineType)
#undef defineType
        MAXType
    }Type;
    JsonObject(Type t);
    JsonObject(const ASString& strJson);
    const Type& type() const { return mType; }

private:
    Type mType;
};

class JsonObjectBase
{
public:
    JsonObjectBase(JsonObject::Type t, const ASString& seq);
    JsonObjectBase(JsonObject* base);
    virtual ~JsonObjectBase();
    const JsonObject::Type& getType() const { return mBaseObj->type(); }
    const ASString& getSequence() const { return mSequence; }
    const ASString& getCommand() const { return mCommand; }
    virtual ASString toString(bool formatted = false); // build only once
    virtual ASString to_string(bool formatted = false) const = 0; // rebuild everytime

protected:
    const neb::CJsonObject& object() const { return *mBaseObj; }
    neb::CJsonObject& object() { return *mBaseObj; }

    JsonObject*     mBaseObj;
    ASString        mSequence;
    ASString        mCommand;
    bool            mBuild;
};

#endif // #ifndef JSON_OBJECT_BASE_HXX
